package com.example.test.advice.第五章_数组和集合.建议79_集合中的哈希码不要重复;

import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Client {

    public static void main(String[] args) {
        testArrayList();
        testeHashMap();
    }

    public static void testeHashMap(){
        int size = 10000;
        Map<String,String> map = new HashMap<>();
        //初始化
        for(int i = 0;i<size;i++){
           map.put("key"+i,"value"+i);
        }

        long start = System.nanoTime();
        map.containsKey("key"+(size-1));
        long end = System.nanoTime();
        System.out.println("map遍历耗时："+(end-start)+"ns");
    }

    public static void testArrayList(){
        int size = 10000;
        List<String> list = new ArrayList<>(size);
        //初始化
        for(int i = 0;i<size;i++){
            list.add("value"+i);
        }

        long start = System.nanoTime();
        list.contains("value"+(size-1));
        long end = System.nanoTime();
        System.out.println("List遍历耗时："+(end - start)+"ns");
    }
}
